﻿Imports System.Data.SqlClient

Public Class clsRecaudacion
    Private mintIdRecaudacion As Integer
    Private mintIdAutobus As Integer
    Private mintIdServicio As Integer
    Private mintIdOperador As Integer
    Private mdatFecha As Date
    Private mintPasajeros As Integer
    Private mdblMonto As Double
    Private mdblMarcasDescontadas As Double
    Private mintMarcasRedondeadas As Integer
    Private mdblMontoDeducciones As Double
    Private mdblMontoMenosDeducciones As Double
    Public Property IdRecaudacion() As Integer
        Get
            Return mintIdRecaudacion
        End Get
        Set(ByVal value As Integer)
            mintIdRecaudacion = value
        End Set
    End Property
    Public Property IdAutobus() As Integer
        Get
            Return mintIdAutobus
        End Get
        Set(ByVal value As Integer)
            mintIdAutobus = value
        End Set
    End Property
    Public Property IdServicio() As Integer
        Get
            Return mintIdServicio
        End Get
        Set(ByVal value As Integer)
            mintIdServicio = value
        End Set
    End Property
    Public Property IdOperador() As Integer
        Get
            Return mintIdOperador
        End Get
        Set(ByVal value As Integer)
            mintIdOperador = value
        End Set
    End Property
    Public Property Fecha() As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property Pasajeros() As Integer
        Get
            Return mintPasajeros
        End Get
        Set(ByVal value As Integer)
            mintPasajeros = value
        End Set
    End Property
    Public Property Monto() As Double
        Get
            Return mdblMonto
        End Get
        Set(ByVal value As Double)
            mdblMonto = value
        End Set
    End Property
    Public Property MarcasDescontadas() As Double
        Get
            Return mdblMarcasDescontadas
        End Get
        Set(ByVal value As Double)
            mdblMarcasDescontadas = value
        End Set
    End Property
    Public Property MarcasRedondeadas() As Integer
        Get
            Return mintMarcasRedondeadas
        End Get
        Set(ByVal value As Integer)
            mintMarcasRedondeadas = value
        End Set
    End Property
    Public Property MontoDeducciones() As Double
        Get
            Return mdblMontoDeducciones
        End Get
        Set(ByVal value As Double)
            mdblMontoDeducciones = value
        End Set
    End Property
    Public Property MontoMenosDeducciones() As Double
        Get
            Return mdblMontoMenosDeducciones
        End Get
        Set(ByVal value As Double)
            mdblMontoMenosDeducciones = value
        End Set
    End Property
    Public Sub New()
        mintIdRecaudacion = 0
        mintIdAutobus = 0
        mintIdServicio = 0
        mintIdOperador = 0
        mdatFecha = Now()
        mintPasajeros = 0
        mdblMonto = 0
        mdblMarcasDescontadas = 0
        mintMarcasRedondeadas = 0
        mdblMontoDeducciones = 0
        mdblMontoMenosDeducciones = 0

    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into Recaudacion (" & _
                            "IdAutobus," & _
                            "IdServicio," & _
                            "IdOperador," & _
                            "Fecha," & _
                            "Pasajeros," & _
                            "Monto," & _
                            "MarcasDescontadas," & _
                            "MarcasRedondeadas," & _
                            "MontoDeducciones," & _
                            "MontoMenosDeducciones)" & _
                            "VALUES (" & _
                            "@IdAutobus," & _
                            "@IdServicio," & _
                            "@IdOperador," & _
                            "@Fecha," & _
                            "@Pasajeros," & _
                            "@Monto," & _
                            "@MarcasDescontadas," & _
                            "@MarcasRedondeadas," & _
                            "@MontoDeducciones," & _
                            "@MontoMenosDeducciones)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("IdServicio", mintIdServicio)
        Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Pasajeros", mintPasajeros)
        Command.Parameters.AddWithValue("Monto", mdblMonto)
        Command.Parameters.AddWithValue("MarcasDescontadas", mdblMarcasDescontadas)
        Command.Parameters.AddWithValue("MarcasRedondeadas", mintMarcasRedondeadas)
        Command.Parameters.AddWithValue("MontoDeducciones", mdblMontoDeducciones)
        Command.Parameters.AddWithValue("MontoMenosDeducciones", mdblMontoMenosDeducciones)
      

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro de recaudación", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Sub Actualizar()
        Dim strSqlQry As String
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        strSqlQry = "Update Recaudacion Set " & _
                            "IdAutobus=@IdAutobus," & _
                            "IdServicio=@IdServicio," & _
                            "IdOperador=@IdOperador," & _
                            "Fecha=@Fecha," & _
                            "Pasajeros=@Pasajeros," & _
                            "Monto=@Monto," & _
                            "MarcasDescontadas=@MarcasDescontadas," & _
                            "MarcasRedondeadas=@MarcasRedondeadas," & _
                            "MontoDeducciones=@MontoDeducciones," & _
                            "MontoMenosDeducciones=@MontoMenosDeducciones " & _
                            " Where IdRecaudacion=@IdRecaudacion"


        Dim Command As New SqlCommand(strSqlQry, cnConn)
        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("IdServicio", mintIdServicio)
        Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Pasajeros", mintPasajeros)
        Command.Parameters.AddWithValue("Monto", mdblMonto)
        Command.Parameters.AddWithValue("MarcasDescontadas", mdblMarcasDescontadas)
        Command.Parameters.AddWithValue("MarcasRedondeadas", mintMarcasRedondeadas)
        Command.Parameters.AddWithValue("MontoDeducciones", mdblMontoDeducciones)
        Command.Parameters.AddWithValue("MontoMenosDeducciones", mdblMontoMenosDeducciones)

        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el registro de roles", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If



    End Sub

End Class
